<template>
  <div style="height: 100%">
    <Info
      v-show="props.isAdmin"
      class="info"
      ref="infoRef"
      v-slot="slotProps"
      :openDraw="openDrawWithCreate"
    >
      <Table
        class="table"
        :tableData="slotProps.tableData"
        :deleteInstructs="slotProps.deleteInstructs"
        :editInstructs="openDrawWithEdit"
        :refresh="slotProps.refresh"
        :changeInstructOpenType="slotProps.changeInstructOpenType"
        :changeInstructIsHigh="slotProps.changeInstructIsHigh"
        :changeInstructDisplay="slotProps.changeInstructDisplay"
        :addInstructDescribe="slotProps.addInstructDescribe"
      ></Table>
    </Info>
    <Edit
      ref="editRef"
      :show="isShowDraw"
      :title="drawTitle"
      :defaultInfo="defaultInfo"
      @visibleChange="(visble) => (isShowDraw = visble)"
      @submitSuccess="submitSuccess"
    ></Edit>
  </div>
</template>

<script setup>
import { ref } from "vue";
import Edit from "./Edit.vue";
import Info from "./Info.vue";
import Table from "./Table.vue";

const props = defineProps({
  isAdmin: Boolean,
});

const infoRef = ref();
const editRef = ref();
const isShowDraw = ref(false);
const drawTitle = ref("");
const defaultInfo = ref(null);

defineExpose({
  refresh: () => infoRef.value.refresh(),
  init: () => editRef.value.init(),
});

const openDrawWithCreate = () => {
  defaultInfo.value = null;
  drawTitle.value = "新增标准指令";
  isShowDraw.value = true;
};
const openDrawWithEdit = (index, row) => {
  defaultInfo.value = row;
  drawTitle.value = "编辑标准指令";
  isShowDraw.value = true;
};
const submitSuccess = () => {
  infoRef.value.refresh();
};
</script>

<style scoped lang="scss">
.table {
  padding: 0 30px;
}
</style>
